//
//  ReplaySubjectViewController.swift
//  testRxSwift
//
//  Created by 火星人 on 2017/7/25.
//  Copyright © 2017年 火星人. All rights reserved.
//

import UIKit
import RxSwift

class ReplaySubjectViewController: BaseViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

        self.view.addTapWithHandle { (tap) in
            
            let disBag = DisposeBag()
            
            let subject = ReplaySubject<String>.createUnbounded()
            
            // 指定缓冲区大小为1，那么订阅者2就不会收到11了
//            let subject = ReplaySubject<String>.create(bufferSize: 1)
            
            subject.subscribe({ (eve) in
                print("1 \(eve)")
            }).disposed(by: disBag)
            
            subject.onNext("11")
            subject.onNext("12")
            
            subject.subscribe({ (eve) in
                print("2 \(eve)")
            }).disposed(by: disBag)
            
            subject.onNext("21")
            subject.onNext("22")
        }
    }

}
